/**
 * Copyright (C) 2009-2012, KingHool.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses.
 */
package com.kinghool.smodel.io.source;


import com.kinghool.smodel.IXmlModel;
import com.kinghool.smodel.XmlModel;
import com.kinghool.smodel.def.ModelDefinition;
import com.kinghool.smodel.def.XmlModelDefinition;
import com.kinghool.smodel.io.IModelChannel;
import com.kinghool.smodel.io.IModelSource;

/**
 * 
 * @Author Allen Deng(dengtailin@gmail.com) 
 */
public class XmlModelSource extends BaseModelSource<IXmlModel> implements IModelSource<IXmlModel> {
 
	public XmlModelSource(IModelChannel channel) {
		super(channel);
	} 

	public IXmlModel newModelInstance(ModelDefinition modelDefinition) {
		checkModelDefinition(modelDefinition);
		return new XmlModel((XmlModelDefinition) modelDefinition);
	}
	
	protected ModelDefinition getModelDefinition(String id) {
		XmlModelDefinition xmlModelDefinition = XmlModelDefinition.createDefaultXmlModelDefinition(id, null);
		return xmlModelDefinition;
	}
	
	protected void checkModelDefinition(ModelDefinition modelDefinition) {
		if (!(modelDefinition instanceof XmlModelDefinition)) {
			throw new IllegalArgumentException("invalid argument modelDefinition: modelDefinition should be XmlModelDefinition");
		}
	} 
}
